package com.seocoo.worker;

import android.Manifest;
import android.os.Bundle;

import com.seocoo.worker.base.Const;
import com.seocoo.worker.base.PermissionUtil;
import com.seocoo.worker.base.entity.ELogin;
import com.seocoo.worker.home.HomeActivity;
import com.seocoo.worker.user.login.LoginActivity;
import com.sfh.lib.AppCacheManager;
import com.sfh.lib.ui.MVVMActivity;
import com.sfh.lib.utils.ThreadTaskUtils;

import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

public class MainActivity extends MVVMActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Future future = ThreadTaskUtils.schedule(new Runnable() {
            @Override
            public void run() {
                onPermission();
            }
        }, 1000, TimeUnit.MILLISECONDS);

        putFuture(future);


    }


    private void onPermission(){
        PermissionUtil.checkPermissions(this, "为了保证您安全、正常的使用APP，当需要获取您定位、存储权限和手机信息时，请点击允许", 10001, new PermissionUtil.PermissionCallBack() {
                    @Override
                    public void onHasPermission() {
                        ELogin login = AppCacheManager.getCacheListener().getObject(Const.LOGIN_KEY, ELogin.class);
                        if (login == null) {
                            LoginActivity.start(MainActivity.this);
                        } else {
                            HomeActivity.startContentUI(MainActivity.this);
                        }
                        finish();
                    }

                    @Override
                    public void onFailedPermission() {

                    }
                },  Manifest.permission.WRITE_SETTINGS,
                Manifest.permission.WRITE_EXTERNAL_STORAGE,
                Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.ACCESS_FINE_LOCATION,
                Manifest.permission.ACCESS_COARSE_LOCATION,
                Manifest.permission.READ_PHONE_STATE);
    }
}
